package collection;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author Created by chenxin34 on 2020/5/24 下午4:02.
 */
public class ListSortTest {
    public static void main(String[] args) {
        List<SortTestObejct> list = new ArrayList<>();
        list.add(new SortTestObejct(2, 1));
        list.add(new SortTestObejct(4, 2));
        list.add(new SortTestObejct(5, 2));
        list.add(new SortTestObejct(1, 2));
        list.add(new SortTestObejct(3, 2));

        list.sort(new ObeCmp());
        System.out.println(list);
    }

    private static class SortTestObejct {

        public SortTestObejct(long id, int score) {
            this.id = id;
            this.score = score;
        }

        public long id;

        public int score;

        @Override
        public String toString() {
            return "SortTestObejct{" +
                    "id:" + id +
                    ", score:" + score +
                    '}';
        }
    }

    private static class ObeCmp implements Comparator<SortTestObejct> {

        @Override
        public int compare(SortTestObejct o1, SortTestObejct o2) {
            return Integer.compare(o1.score, o2.score);
        }
    }
}
